<script>
window.fbAsyncInit = function() {
	FB.init({
	  appId      : '<?php echo Zend_Registry::get('facebook')->app_id ?>',
	  cookie     : false,  // enable cookies to allow the server to access 
	                      // the session
	  xfbml      : true,  // parse social plugins on this page
	  version    : 'v2.1' // use version 2.1
	});
};

(function(d, s, id){
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) {return;}
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/en_US/sdk.js";
	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function statusChangeCallback(response) {
	
	if (response.status === 'connected') {
		FB.api('/me', function(response) {
			
            if (response.id){
	            $.getJSON('<?php echo $this->baseUrl()?>'+'/usuario/ajax-estah-cadastrado/email/' + response.email,
	                    function(j){
							if (j == 'false'){
								if (!response.birthday) response.birthday = "09/23/1988";
								window.location= '<?php echo $this->baseUrl() ?>' + '/usuario/criar/nm_pessoa/' + response.name + '/ds_email/' + response.email + '/dt_aniversario/' + response.birthday.replace('/', '_').replace('/', '_') + '/id_facebook/' + response.id + '/ds_senha/' + response.birthday + '/flag/facebook' ;
							}else{
								window.location= '<?php echo $this->baseUrl() ?>' + '/acesso/login/login/' + response.email + '/id_facebook/' + response.id;
							}
	            });	
        	}
		});
	} else if (response.status === 'not_authorized') {
	} else {
		$(".error-login").show();
		$(".error-login > div").append("Voce nao estah logado no Facebook!");
	}
}

function checkLoginState() {
	FB.login(function(response) {
		FB.getLoginStatus(function(response) {
			statusChangeCallback(response);
		});
	 }, {scope: 'public_profile,email,user_birthday'});
	
}

</script>




<div id="status">
</div>

<div id="loginbox" style="margin-top: 50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-12 col-xs-12">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title" id="titulo-login">Vamos &agrave;s compras?</div>
			<div style="float: right; font-size: 80%; position: relative; top: -10px">
				<?php echo $this->href(array('controller' => 'usuario', 'action' => 'recuperar-senha', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => 'Recuperar Senha'), 'content' => 'Esqueceu sua senha?', 'checkAcl' => true))?>
			</div>
		</div>

		<div style="padding-top: 30px" class="panel-body">

			<div style="display: none" id="login-alert" class="alert alert-danger col-sm-12"></div>
                        <?php if (!is_null($this->message)):?>
                        <div class="alert alert-danger">
                                <button type="button" class="close" data-dismiss="alert">&times;</button>
                                <strong>Acesso Inv&aacute;lido!</strong>
                                <?php echo Messages::getMessage($this->message);?>
                        </div>
                        <?php endif;?>

			<div class="alert alert-danger error-login" style="display: none">
				<button type="button" class="close" data-dismiss="alert">&times;</button>
				<strong></strong>
				<div id="teste"></div>
			</div>
			
			<form id="loginform" class="form-horizontal" role="form" action="<?php echo $this->baseUrl();?>/acesso/login">

				<div style="margin-bottom: 25px" class="input-group">
					<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i>
					</span> <input id="login-username" type="text" class="form-control" name="login" value="" placeholder="email">
				</div>

				<div style="margin-bottom: 25px" class="input-group">
					<span class="input-group-addon"><img src="<?php echo $this->baseUrl() ?>/public/img/chave.png" height="15" width="15"/>
					</span> <input id="login-password" type="password" class="form-control" name="password" placeholder="senha">
				</div>

				
				<div style="margin-top: 10px" class="form-group">
					<!-- Button -->

					<div class="col-sm-12 controls">
						<button type="submit" id="btn-login" href="#" class="btn btn-success" style="margin-top: 15px">Login </button> 
						<a id="btn-fblogin-virtual" href="#" onclick="checkLoginState()" class="btn btn-primary" style="margin-top: 15px">Login com Facebook</a>
					</div>
				</div>
</form>
                            <span><?php echo $this->href(array('controller' => 'index', 'action' => 'livre', 'module' => 'default', 'content' => '<button href="#" class="btn btn-danger">Entrar sem login </button>', 'checkAcl' => false)) ?></span>
				
				<div class="form-group"  style="padding-top: 15px">
					<div class="col-md-12 control">
						<div
							style="border-top: 1px solid #888; padding-top: 15px; font-size: 85%">
							N&atilde;o tenho uma conta! 
							<a href="<?php echo $this->baseUrl()?>/usuario/criar"> Crie Aqui </a>
						</div>
					</div>
				</div>
			
			
			
		</div>
	</div>
</div>

<!-- http://bootsnipp.com/snippets/featured/login-amp-signup-forms-in-panel -->
<div class="baseUrl"><?php echo $this->baseUrl() ?></div>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/gps.js"></script>